package com.android.equipment.ui.dialog

import android.content.Context
import com.android.equipment.R
import com.android.equipment.adapter.SelectPeopleAdapter
import com.android.equipment.bean.WorkDetailPeopleData
import com.android.equipment.databinding.DialogSelectPeopleBinding
import com.lxj.xpopup.core.BottomPopupView

class SelectPeopleDialog(context: Context, val peopleList: MutableList<WorkDetailPeopleData>, val listener: SelectPeopleListener) : BottomPopupView(context) {
    val selectPeopleAdapter: SelectPeopleAdapter by lazy {
        SelectPeopleAdapter(R.layout.item_people_select)
    }

    val binding: DialogSelectPeopleBinding by lazy {
        DialogSelectPeopleBinding.bind(popupImplView)
    }

    override fun getImplLayoutId(): Int {
        return R.layout.dialog_select_people
    }

    override fun onCreate() {
        super.onCreate()
        initRecycler()
    }


    private fun initRecycler(){
        binding.rvPeople.adapter = selectPeopleAdapter
        selectPeopleAdapter.setList(peopleList)
        selectPeopleAdapter.setOnItemClickListener { adapter, view, position ->
            val item = adapter.getItem(position)
            listener.onSelectPeopleClick(item as WorkDetailPeopleData)
            dismiss()
        }
    }

    interface SelectPeopleListener {
        fun onSelectPeopleClick(people: WorkDetailPeopleData)
    }
}